/*************************************************************************
 *                                                                       *
 * This file is part of the FreeMAPs distribution.  For full copyright   *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 * Date:             2011.09.18                                          *
 *                                                                       *
 *************************************************************************/

//declaration header
#include "COMMON/bdry/InitializationCondition.h"

//COMMON headers
#include "COMMON/bdry/IrregularBoundaryConditionStrategy.h"
#include "COMMON/equa/PDEEquationEnsembleStrategy.h"
#include "COMMON/info/InfoManager.h"
#include "COMMON/tbox/LogMessage.h"


namespace FreeMAPs
{

InitializationCondition::InitializationCondition (
    const std::string& parent_name,
    const std::string& ic_name):
    Parent                      (parent_name, ic_name, false),
    d_is_value_out_of_range_set (false),
    d_value_out_of_range        (0.),
    d_only_act_on_init          (true),
    d_start_time                (0.),
    d_end_time                  (0.),
    d_init_value                (300),
    d_variable_complete_symbol("T")
{}



InitializationCondition::~InitializationCondition()
{
    this->clear();
}



void
InitializationCondition::clear()
{
    //Utilities::clear_pointer_object (d_init_value);
    d_inside_level_sets.clear();
    d_outside_level_sets.clear();
}



void
InitializationCondition::get_from_input (
    const InputDatabase* db,
    const PDEEquationEnsembleStrategy& equation_ensemble)
{
    this->prepare_for_use (db);

    db->insert_allowable_key ("variable_symbol");
    db->insert_allowable_key ("range");
    db->insert_allowable_key ("init_value");
#ifdef FREEMAPS_HAVE_SAMRAI
    db->insert_allowable_key ("inside_level_sets");
    db->insert_allowable_key ("outside_level_sets");
#endif
    db->insert_allowable_key ("value_out_of_range");
    db->insert_allowable_key ("start_time");
    db->insert_allowable_key ("end_time");

    db->check_allowable_keys ();

    /*
     * build variable_symbol
     */
    if(db->key_exists("variable_symbol") && db->is_string("variable_symbol"))
    {
        db->check_requisite_key ("variable_symbol", DataType::STRING, false, false);
        d_variable_complete_symbol = db->get_string ("variable_symbol");
    }

    /*
     * build init_value
     */
    if(db->key_exists("init_value") && db->is_double("init_value"))
    {
        db->check_requisite_key ("init_value", DataType::DOUBLE, false, false);
        d_init_value = db->get_double("init_value");
    }
}



std::ostream&
operator << (
    std::ostream& os,
    const InitializationCondition& rhs)
{
    os << "variable_symbol = \"" << rhs.d_variable_complete_symbol << "\"\n";

//    oss << *rhs.d_init_value;
    os << "init_value = " << rhs.d_init_value ;

    return os;
}

}
